package ljl.alg.jianzhioffer.round3.medium;

/**
 * 有点难，而且只看代码，你还看不懂
 * */
public class _46_translateNum {

    class left_to_right {
        public int translateNum(int num) {
            String s = String.valueOf(num);
            int a = 1, b = 1;
            for(int i = 2; i <= s.length(); i++) {
                String tmp = s.substring(i - 2, i);
                int c = tmp.compareTo("10") >= 0 && tmp.compareTo("25") <= 0 ? a + b : a;
                b = a;
                a = c;
            }
            return a;
        }
    }

    class right_to_left {
        public int translateNum(int num) {
            String s = String.valueOf(num);
            int a = 1, b = 1;
            for(int i = s.length() - 2; i > -1; i--) {
                String tmp = s.substring(i, i + 2);
                int c = tmp.compareTo("10") >= 0 && tmp.compareTo("25") <= 0 ? a + b : a;
                b = a;
                a = c;
            }
            return a;
        }
    }

    /**
     * 怎么样这个变量名起的
     * 我就说了不好理解吧。其实不难
     * */
    public int translateNum(int num) {
        int a = 1, b = 1, c, d = num % 10;
        while (num > 0) {
            num /= 10;
            c = num % 10;
            int e = c * 10 + d;
            int f = e >= 10 && e <= 25 ? a + b : a;
            b = a;
            a = f;
            d = c;
        }
        return a;
    }

    class clever {
        public int translateNum(int num) {
            int a = 1, b = 1, x, y = num % 10;
            while(num != 0) {
                num /= 10;
                x = num % 10;
                int tmp = 10 * x + y;
                int c = (tmp >= 10 && tmp <= 25) ? a + b : a;
                b = a;
                a = c;
                y = x;
            }
            return a;
        }

    }


}
